<template>
  <div class="page-container">
    <div class="page-header">
      <h2>学习分析</h2>
    </div>

    <!-- 学习概览 -->
    <div class="overview-section">
      <div class="overview-card">
        <div class="overview-icon">⏱️</div>
        <div class="overview-content">
          <div class="overview-title">本周学习时长</div>
          <div class="overview-number">{{ studyStats.weeklyHours }}h</div>
          <div class="trend up">↑ 较上周增长2h</div>
        </div>
      </div>
      <div class="overview-card">
        <div class="overview-icon">📈</div>
        <div class="overview-content">
          <div class="overview-title">平均成绩</div>
          <div class="overview-number">{{ studyStats.averageScore }}</div>
          <div class="trend up">↑ 较上月提升3分</div>
        </div>
      </div>
      <div class="overview-card">
        <div class="overview-icon">🎯</div>
        <div class="overview-content">
          <div class="overview-title">完成任务数</div>
          <div class="overview-number">{{ studyStats.completedTasks }}</div>
          <div class="trend up">↑ 超额完成5个</div>
        </div>
      </div>
    </div>

    <!-- 成绩分析 -->
    <div class="analysis-section">
      <div class="analysis-card performance">
        <h3>各项能力分析</h3>
        <div class="skills-analysis">
          <div v-for="skill in skillsAnalysis" :key="skill.type" class="skill-item">
            <div class="skill-header">
              <span class="skill-name">{{ skill.name }}</span>
              <span class="skill-score">{{ skill.score }}分</span>
            </div>
            <div class="progress-bar">
              <div class="progress-fill" :style="{ width: skill.score + '%', background: skill.color }"></div>
            </div>
            <p class="skill-comment">{{ skill.comment }}</p>
          </div>
        </div>
      </div>

      <!-- 学习时间分布 -->
      <div class="analysis-card time-distribution">
        <h3>学习时间分布</h3>
        <div class="time-chart">
          <div v-for="(time, day) in timeDistribution" :key="day" class="time-bar">
            <div class="bar-wrapper">
              <div class="bar-fill" :style="{ height: `${time * 40}px` }">
                <span class="bar-value">{{ time }}h</span>
              </div>
            </div>
            <div class="bar-label">{{ day }}</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 学习建议 -->
    <div class="suggestions-section">
      <h3>学习建议</h3>
      <div class="suggestions-grid">
        <div v-for="suggestion in learningTips" :key="suggestion.id" class="suggestion-card">
          <div class="suggestion-icon">{{ suggestion.icon }}</div>
          <div class="suggestion-content">
            <h4>{{ suggestion.title }}</h4>
            <p>{{ suggestion.content }}</p>
          </div>
        </div>
      </div>
    </div>

    <!-- 最近错题分析 -->
    <div class="mistakes-section">
      <h3>最近错题分析</h3>
      <div class="mistakes-list">
        <div v-for="mistake in recentMistakes" :key="mistake.id" class="mistake-card">
          <div class="mistake-header">
            <span class="mistake-type" :class="mistake.type">{{ getTypeName(mistake.type) }}</span>
            <span class="mistake-date">{{ mistake.date }}</span>
          </div>
          <div class="mistake-content">
            <p class="mistake-question">{{ mistake.question }}</p>
            <div class="mistake-analysis">
              <h5>错误分析：</h5>
              <p>{{ mistake.analysis }}</p>
            </div>
            <div class="mistake-suggestion">
              <h5>改进建议：</h5>
              <p>{{ mistake.suggestion }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'StudentAnalysis',
  data() {
    return {
      studyStats: {
        weeklyHours: 12.5,
        averageScore: 88,
        completedTasks: 25
      },
      skillsAnalysis: [
        {
          type: 'vocabulary',
          name: '词汇量',
          score: 85,
          color: '#409eff',
          comment: '词汇积累稳步提升，建议继续扩充专业词汇'
        },
        {
          type: 'listening',
          name: '听力理解',
          score: 78,
          color: '#67c23a',
          comment: '听力基础扎实，需加强快速反应能力'
        },
        {
          type: 'reading',
          name: '阅读理解',
          score: 92,
          color: '#e6a23c',
          comment: '阅读能力突出，可以尝试更有挑战的材料'
        },
        {
          type: 'speaking',
          name: '口语表达',
          score: 75,
          color: '#f56c6c',
          comment: '发音准确度需要提高，建议多进行口语练习'
        }
      ],
      timeDistribution: {
        周一: 2.5,
        周二: 1.8,
        周三: 2.0,
        周四: 1.5,
        周五: 2.2,
        周六: 1.3,
        周日: 1.2
      },
      learningTips: [
        {
          id: 1,
          icon: '🎯',
          title: '专注力提升',
          content: '建议使用番茄工作法，每次学习25分钟，休息5分钟'
        },
        {
          id: 2,
          icon: '📚',
          title: '词汇积累',
          content: '利用碎片时间记忆单词，每天坚持记录生词本'
        },
        {
          id: 3,
          icon: '🎧',
          title: '听力训练',
          content: '每天听10分钟英语新闻或歌曲，培养语感'
        },
        {
          id: 4,
          icon: '✍️',
          title: '写作提高',
          content: '每周完成一篇短文写作，注重句型变换和词汇运用'
        }
      ],
      recentMistakes: [
        {
          id: 1,
          type: 'vocabulary',
          date: '2024-02-11',
          question: 'Determine the correct usage of "affect" vs "effect"',
          analysis: '混淆了affect(动词,影响)和effect(名词,效果)的用法',
          suggestion: '记忆技巧：A for Action (affect作为动词), E for End result (effect作为结果)'
        },
        {
          id: 2,
          type: 'listening',
          date: '2024-02-10',
          question: 'Listen and choose the correct response in a business context',
          analysis: '未能准确识别商务场景中的专业词汇',
          suggestion: '多听商务英语对话，积累相关词汇和表达方式'
        },
        {
          id: 3,
          type: 'reading',
          date: '2024-02-09',
          question: 'Reading comprehension about environmental protection',
          analysis: '对文章中的因果关系理解不够深入',
          suggestion: '阅读时注意划分段落层次，理清文章逻辑关系'
        }
      ]
    }
  },
  methods: {
    getTypeName(type) {
      const typeMap = {
        vocabulary: '词汇',
        listening: '听力',
        reading: '阅读',
        speaking: '口语',
        writing: '写作'
      }
      return typeMap[type] || type
    }
  }
}
</script>

<style scoped>
.page-container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.overview-section {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 30px;
}

.overview-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px solid #dcdfe6;
}

.overview-icon {
  font-size: 24px;
}

.overview-content {
  flex: 1;
}

.overview-title {
  font-size: 14px;
  color: #909399;
  margin-bottom: 8px;
}

.overview-number {
  font-size: 24px;
  color: #303133;
  font-weight: 500;
  margin-bottom: 8px;
}

.trend {
  font-size: 12px;
}

.trend.up {
  color: #67c23a;
}

.trend.down {
  color: #f56c6c;
}

.analysis-section {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 30px;
}

.analysis-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  border: 1px solid #dcdfe6;
}

.analysis-card h3 {
  margin: 0 0 20px 0;
  font-size: 16px;
  color: #303133;
}

.skills-analysis {
  display: grid;
  gap: 20px;
}

.skill-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.skill-name {
  font-size: 14px;
  color: #606266;
}

.skill-score {
  font-size: 14px;
  color: #303133;
  font-weight: 500;
}

.progress-bar {
  height: 6px;
  background: #f0f2f5;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  transition: width 0.3s ease;
}

.skill-comment {
  margin: 0;
  font-size: 12px;
  color: #909399;
}

.time-chart {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 20px 10px;
  margin-top: 20px;
}

.time-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 40px;
}

.bar-wrapper {
  width: 24px;
  height: 150px;
  display: flex;
  align-items: flex-end;
  margin-bottom: 8px;
}

.bar-fill {
  width: 100%;
  background: #409eff;
  border-radius: 4px 4px 0 0;
  position: relative;
  transition: height 0.3s ease;
}

.bar-value {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: #606266;
  white-space: nowrap;
}

.bar-label {
  font-size: 12px;
  color: #909399;
  text-align: center;
}

.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.suggestion-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  border: 1px solid #dcdfe6;
  display: flex;
  gap: 16px;
}

.suggestion-icon {
  font-size: 24px;
}

.suggestion-content h4 {
  margin: 0 0 8px 0;
  font-size: 16px;
  color: #303133;
}

.suggestion-content p {
  margin: 0;
  font-size: 14px;
  color: #606266;
  line-height: 1.5;
}

.mistakes-list {
  display: grid;
  gap: 20px;
}

.mistake-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  border: 1px solid #dcdfe6;
}

.mistake-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.mistake-type {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: white;
}

.vocabulary {
  background: #409eff;
}
.listening {
  background: #67c23a;
}
.reading {
  background: #e6a23c;
}
.speaking {
  background: #f56c6c;
}
.writing {
  background: #909399;
}

.mistake-date {
  font-size: 12px;
  color: #909399;
}

.mistake-question {
  font-size: 14px;
  color: #303133;
  margin: 0 0 16px 0;
}

.mistake-analysis h5,
.mistake-suggestion h5 {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: #303133;
}

.mistake-analysis p,
.mistake-suggestion p {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: #606266;
  line-height: 1.5;
}

@media (max-width: 768px) {
  .overview-section,
  .analysis-section {
    grid-template-columns: 1fr;
  }
}
</style>
